@@ -283,23 +283,35 @@ def register(self, app: "Flask", options: dict) -> None:
283283 name the blueprint is registered with. This allows the same
284284 blueprint to be registered multiple times with unique names
285285 for ``url_for``.
286- """
287- first_registration = True
288-
289- for blueprint in app .blueprints .values ():
290- if blueprint is self :
291- first_registration = False
292286
287+ .. versionchanged:: 2.0.1
288+ Registering the same blueprint with the same name multiple
289+ times is deprecated and will become an error in Flask 2.1.
290+ """
291+ first_registration = not any (bp is self for bp in app .blueprints .values ())
293292 name_prefix = options .get ("name_prefix" , "" )
294293 self_name = options .get ("name" , self .name )
295294 name = f"{ name_prefix } .{ self_name } " .lstrip ("." )
296295
297- if name in app .blueprints and app .blueprints [name ] is not self :
298- raise ValueError (
299- f"Blueprint name '{ self .name } ' "
300- f"is already registered by { app .blueprints [self .name ]} . "
301- "Blueprints must have unique names."
302- )
296+ if name in app .blueprints :
297+ existing_at = f" '{ name } '" if self_name != name else ""
298+
299+ if app .blueprints [name ] is not self :
300+ raise ValueError (
301+ f"The name '{ self_name } ' is already registered for"
302+ f" a different blueprint{ existing_at } . Use 'name='"
303+ " to provide a unique name."
304+ )
305+ else :
306+ import warnings
307+
308+ warnings .warn (
309+ f"The name '{ self_name } ' is already registered for"
310+ f" this blueprint{ existing_at } . Use 'name=' to"
311+ " provide a unique name. This will become an error"
312+ " in Flask 2.1." ,
313+ stacklevel = 4 ,
314+ )
303315
304316 app .blueprints [name ] = self
305317 self ._got_registered_once = True
0 commit comments