Commit 33be11b6 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fix legacy environment name collisions with non legacy definitions.

parent b84c3a70
......@@ -2618,15 +2618,22 @@ class Environment(MSection):
return all_definitions_by_name
def resolve_definitions(self, name: str, section_cls: Type[MSectionBound]) -> List[MSectionBound]:
def resolve_definitions(
self, name: str, section_cls: Type[MSectionBound],
filter: TypingCallable[[MSection], bool] = None) -> List[MSectionBound]:
return [
definition
for definition in self.all_definitions_by_name.get(name, [])
if isinstance(definition, section_cls)
if not (isinstance(definition, Section) and definition.extends_base_section)]
if not (isinstance(definition, Section) and definition.extends_base_section)
if filter is None or filter(definition)]
def resolve_definition(
self, name, section_cls: Type[MSectionBound],
filter: TypingCallable[[MSection], bool] = None) -> MSectionBound:
def resolve_definition(self, name, section_cls: Type[MSectionBound]) -> MSectionBound:
defs = self.resolve_definitions(name, section_cls)
defs = self.resolve_definitions(name, section_cls, filter=filter)
if len(defs) == 1:
return defs[0]
elif len(defs) > 1:
......
......@@ -203,6 +203,10 @@ class Backend(AbstractParserBackend):
warnings and errors.
'''
@staticmethod
def filter_legacy_defs(definition):
return definition.m_get_annotations('legacy') is not None
def __init__(
self, metainfo: Union[str, LegacyMetainfoEnvironment], domain: str = None,
logger=None):
......@@ -252,7 +256,8 @@ class Backend(AbstractParserBackend):
return self.__legacy_env
def resolve_definition(self, name, section_cls: Type[MSectionBound]) -> MSectionBound:
return self.env.resolve_definition(normalize_name(name), section_cls)
return self.env.resolve_definition(
normalize_name(name), section_cls, Backend.filter_legacy_defs)
def resolve_context(self, context_uri: str):
path = context_uri.strip('/').split('/')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment