note: A user-defined top-level module with name "XXX" is not supported
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
I get the following unexpected error.
mypy graph.py
Then, I got the following error.
mypy: "abc.py" shadows library module "abc"
note: A user-defined top-level module with name "abc" is not supported
In the same folder there is a file named abc.py. However I did not check the 'abc.py'. Why I got this kind of error ??
To Reproduce
# graph.py
from collections import defaultdict
from typing import Generic, NewType, TypeVar, Union, List
Restaurant = NewType('Restaurant', str)
Recipe = NewType('Recipe', str)
Node = TypeVar("Node")
Edge = TypeVar("Edge")
class Graph(Generic[Node, Edge]):
def __init__(self):
self.edges: dict[Node, List[Edge]] = defaultdict(list)
def add_relation(self, node: Node, to: Edge):
self.edges[node].append(to)
def get_relations(self, node: Node) -> List[Edge]:
return self.edges[node]
restaurants: Graph[Restaurant, Restaurant] = Graph()
recipes: Graph[Recipe, Recipe] = Graph()
restaurant_dishes: Graph[Restaurant, Recipe] = Graph()
recipes.add_relation(Recipe('Pasta Bolognese'),
Recipe('Pasta with Sausage and Basil'))
restaurant_dishes.add_relation(Restaurant('Viafores'),
Recipe('Pasta Bolognese'))
# abc.py
import collections
import collections.abc
from typing import Set
def get_nutrition_information(text):
return "arugula"
def get_aliases(text):
if text == 'rocket':
return ['arugula']
class AliasedIngredients(collections.abc.Set):
def __init__(self, ingredients: set[str]):
self.ingredients = ingredients
def __contains__(self, value: str):
return value in self.ingredients or any(alias in self.ingredients for alias in get_aliases(value))
def __iter__(self):
return iter(self.ingredients)
def __len__(self):
return len(self.ingredients)
ingredients = AliasedIngredients({'arugula', 'eggplant', 'pepper'})
assert ingredients == {'arugula', 'eggplant', 'pepper'}
assert len(ingredients) == 3
assert 'arugula' in ingredients
assert 'rocket' in ingredients
Expected Behavior
Actual Behavior
Your Environment
- Mypy version used: mypy 1.5.1 (compiled: no)
- Mypy command-line flags: unknown
- Mypy configuration options from
mypy.ini(and other config files):unknown - Python version used:3.8.18
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the mentioned graph.py and abc.py files by running mypy graph.py. Start by tracing how mypy handles the user-defined abc.py alongside the library abc module and its module-shadowing diagnostic. Done should mean the intended behavior for this reproducible case is established and the reported diagnostic is corrected or clearly resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100