| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
| |
* Add inference tips for dataclass attributes
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
|
|
|
|
| |
for more information, see https://pre-commit.ci
|
| |
|
| |
|
| |
|
|
|
|
|
| |
* Use scope parent
* Do not set name onto parent frame for partials
* Add test case that captures broken scopes
|
|
|
|
|
| |
* Infer the type of the result of calling typing.cast()
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
|
| |
|
| |
|
| |
|
| |
|
|
|
|
| |
* Fix link in license header
* Fix link to cpython
|
| |
|
| |
|
| |
|
|
|
|
| |
See https://github.com/PyCQA/astroid/pull/1069\#issuecomment-865206120
|
| |
|
|
|
|
| |
See https://github.com/PyCQA/astroid/pull/1045\#discussion_r654572722
|
| |
|
|
|
|
| |
And add PY3X type constants in it.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Add DynamicClassAttribute to list of properties
DynamicClassAttribute is a descriptor defined in Python's Lib/types.py
which changes the behaviour of an attribute depending on if it is looked
up on the class or on an instance.
* Add fake "name" property to enum.Enum subclasses
Ref PyCQA/pylint#1932. Ref PyCQA/pylint#2062. The enum.Enum class itself
defines two @DynamicClassAttribute data-descriptors "name" and "value"
which behave differently when looked up on an instance or on the class.
When dealing with inference of an arbitrary instance of the enum class,
e.g. in a method defined in the class body like:
class SomeEnum(enum.Enum):
def method(self):
self.name # <- here
we should assume that "self.name" is the string name of some enum
member, unless the enum itself defines a "name" member.
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Fix uncaught AstroidSyntaxErrors in namedtuple brain
Ref #920. This adds a test suite and updates the infer_named_tuple brain with
some additional behaviours expected by `collections.namedtuple`, specifically
about rejecting invalid type and field names. Some of these cases inferred as
namedtuples/`ClassDef` when they would have raised `ValueError` and some of
these raise unhandled `AstroidSyntaxError`s due to attempts to parse class
fakes with type names that would have raised `ValueError`. For example:
from collections import namedtuple
Tuple = namedtuple('X', 'abc abc')
# Traceback (most recent call last):
# ...
# ValueError: Encountered duplicate field name: 'abc'
import astroid
node = astroid.extract_node("""
from collections import namedtuple
Tuple = namedtuple('X', 'abc abc')
Tuple
""")
next(node.infer())
# <ClassDef.X l.3 at 0x...>
from collections import namedtuple
Tuple = namedtuple('123', 'abc')
# Traceback (most recent call last):
# ...
# ValueError: Type names and field names must be valid identifiers: '123'
import astroid
node = astroid.extract_node("""
from collections import namedtuple
Tuple = namedtuple('123', 'abc')
Tuple
""")
next(node.infer())
# Traceback (most recent call last):
# ...
# KeyError: (<function infer_named_tuple at 0x...>, <Call l.3 at 0x...>)
#
# During handling of the above exception, another exception occurred:
#
# Traceback (most recent call last):
# ...
# File "<unknown>", line 2
# class 123(tuple):
# ^
# SyntaxError: invalid syntax
#
# The above exception was the direct cause of the following exception:
#
# Traceback (most recent call last):
# ...
# astroid.exceptions.AstroidSyntaxError: Parsing Python code failed:
# invalid syntax (<unknown>, line 2)
|
|
|
|
|
| |
transformations (#975)
* Fix six.with_metaclass transformation so it doesn't break user defined transformations
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Add test of crash on random.sample inference
Ref #922
* Fix crash in brain for random.sample
Fixes #922. A combination of changes in 79d5a3a7 and 77e205dc meant that
the node cloning helper could be given an EvaluatedObject, which doesn't
present the same __init__ signature as NodeNG.
* Update changelog
|
| |
|
| |
|
| |
|
| |
|
|
|
|
| |
Except on astroid/__init__.py because of circular imports
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
| |
Remove outdated COPYING and rename COPYING.LESSER
|
|
|
|
|
|
|
| |
``__class_getitem__`` (#931)
* Modify infernce tip for typing.Generic and typing.Annotated with __class_getitem__
* Fix issue with slots caching
* Clean typing.Generic from mro
|
|
|
|
|
|
| |
* Better handling of generic aliases
* Use qname for tests mro
* Add inference for re.Pattern and re.Match
* Add comments
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Takes into account the fact that inferring subscript when the node is a class may use the __class_getitem__ method of the current class instead of looking for __getitem__ in the metaclass.
* OrderedDict in the collections module inherit from dict which is C coded and thus have no metaclass but starting from python3.9 it supports subscripting thanks to the __class_getitem__ method.
* check_metaclass becomes a static class method because we need it in the class scope.
The brain_typing module does not add a ABCMeta_typing class thus there is no need to test it. Moreover it doesn't add neither a __getitem__ to the metaclass
* The brain_typing module does not add anymore _typing suffixed classes in the mro
* The OrderedDict class inherits from C coded dict class and thus doesn't have a metaclass.
* When trying to inherit from typing.Pattern the REPL says : TypeError: type 're.Pattern' is not an acceptable base type
* The REPL says that Derived as ABCMeta for metaclass and the mro is Derived => Iterator => Iterable => object
* Adds comments
* Starting with Python39 some collections of the collections.abc module support subscripting thanks to __class_getitem__ method. However the wat it is implemented is not straigthforward and instead of complexifying the way __class_getitem__ is handled inside the getitem method of the ClassDef class, we prefer to hack a bit.
* Thanks to __class_getitem__ method there is no need to hack the metaclass
* SImplifies the inference system for typing objects before python3.9. Before python3.9 the objects of the typing module that are alias of the same objects in the collections.abc module have subscripting possibility thanks to the _GenericAlias metaclass. To mock the subscripting capability we add __class_getitem__ method on those objects.
* check_metaclass_is_abc become global to be shared among different classes
* Create a test class dedicated to the Collections brain
* Rewrites and adds test
* Corrects syntax error
* Deque, defaultdict and OrderedDict are part of the _collections module which is a pure C lib. While letting those class mocks inside collections module is fair for astroid it leds to pylint acceptance tests fail.
* Formatting according to black
* Adds two entries
* Extends the filter to determine what is subscriptable to include OrderedDict
* Formatting according to black
* Takes into account the fact that inferring subscript when the node is a class may use the __class_getitem__ method of the current class instead of looking for __getitem__ in the metaclass.
* OrderedDict in the collections module inherit from dict which is C coded and thus have no metaclass but starting from python3.9 it supports subscripting thanks to the __class_getitem__ method.
* check_metaclass becomes a static class method because we need it in the class scope.
The brain_typing module does not add a ABCMeta_typing class thus there is no need to test it. Moreover it doesn't add neither a __getitem__ to the metaclass
* The brain_typing module does not add anymore _typing suffixed classes in the mro
* The OrderedDict class inherits from C coded dict class and thus doesn't have a metaclass.
* When trying to inherit from typing.Pattern the REPL says : TypeError: type 're.Pattern' is not an acceptable base type
* The REPL says that Derived as ABCMeta for metaclass and the mro is Derived => Iterator => Iterable => object
* Adds comments
* Starting with Python39 some collections of the collections.abc module support subscripting thanks to __class_getitem__ method. However the wat it is implemented is not straigthforward and instead of complexifying the way __class_getitem__ is handled inside the getitem method of the ClassDef class, we prefer to hack a bit.
* Thanks to __class_getitem__ method there is no need to hack the metaclass
* SImplifies the inference system for typing objects before python3.9. Before python3.9 the objects of the typing module that are alias of the same objects in the collections.abc module have subscripting possibility thanks to the _GenericAlias metaclass. To mock the subscripting capability we add __class_getitem__ method on those objects.
* check_metaclass_is_abc become global to be shared among different classes
* Create a test class dedicated to the Collections brain
* Rewrites and adds test
* Corrects syntax error
* Deque, defaultdict and OrderedDict are part of the _collections module which is a pure C lib. While letting those class mocks inside collections module is fair for astroid it leds to pylint acceptance tests fail.
* Formatting according to black
* Adds two entries
* Extends the filter to determine what is subscriptable to include OrderedDict
* Formatting according to black
* Takes into account AWhetter remarks
* Deactivates access to __class_getitem__ method
* OrderedDict appears in typing module with python3.7.2
* _alias function in the typing module appears with python3.7
* Formatting according to black
* _alias function is used also for builtins type and not only for collections.abc ones
* Adds tests for both builtins type that are subscriptable and typing builtin alias type that are also subscriptable
* No need to handle builtin types in this brain. It is better suited inside brain_bulitin_inference
* Adds brain to handle builtin types that are subscriptable starting with python39
* Formatting according to black
* Uses partial function instead of closure in order pylint acceptance to be ok
* Handling the __class_getitem__ method associated to EmptyNode for builtin types is made directly inside the getitem method
* infer_typing_alias has to be an inference_tip to avoid interferences between typing module and others (collections or builtin)
* Formatting
* Removes useless code
* Adds comment
* Takes into account cdce8p remarks
* Formatting
* Style changes
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
|
| |
|
|
|
|
|
|
|
| |
* Adds inference support for all typing types that are defined through _alias function
* Instead of creating a new class (by the mean of TYPING_TYPE_TEMPLATE) infer the origin class : i.e MutableSet = _alias(collections.MutableSet ...) origin is the class in collections module. Needs to add __getitem method on its metaclass so that is support indexing (MutableSet[T]).
* Enable _alias mocking and testing only if python version is at least 3.7
Co-authored-by: hippo91 <guillaume.peillex@gmail.com>
|
| |
|
|
|
| |
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
|
| |
|
| |
|
| |
|