summaryrefslogtreecommitdiff
path: root/tests/unittest_brain.py
Commit message (Collapse)AuthorAgeFilesLines
...
* Add inference tips for dataclass attributes (#1126)David Liu2021-08-161-45/+0
| | | | | * Add inference tips for dataclass attributes Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
* [pre-commit.ci] auto fixes from pre-commit.com hookspre-commit-ci[bot]2021-08-121-1/+1
| | | | for more information, see https://pre-commit.ci
* Remove early return in _is_enum_subclassDavid Liu2021-08-121-5/+27
|
* Support inference of Enum subclasses.David Liu2021-08-121-0/+77
|
* Bump astroid to 2.6.6, update changelogv2.6.6Pierre Sassoulas2021-08-031-0/+2
|
* Fix incorrect scope for functools partials (#1097)Alphadelta142021-08-011-0/+40
| | | | | * 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() (#1076)Tim Martin2021-07-301-0/+32
| | | | | * Infer the type of the result of calling typing.cast() Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
* Bump astroid to 2.6.4, update changelogPierre Sassoulas2021-07-201-1/+1
|
* Bump astroid to 2.6.3, update changelogv2.6.3Pierre Sassoulas2021-07-191-1/+1
|
* Make TypedDict instance callableMarc Mueller2021-07-191-3/+12
|
* Fix 'Consider using an in-place tuple instead of list'Pierre Sassoulas2021-07-101-5/+5
|
* Fix copyright links (#1084)Marc Mueller2021-07-011-1/+1
| | | | * Fix link in license header * Fix link to cpython
* Bump astroid to 2.6.2, update changelogv2.6.2Pierre Sassoulas2021-06-301-1/+1
|
* Bump astroid to 2.6.1, update changelogv2.6.1Pierre Sassoulas2021-06-291-1/+1
|
* Add dict as base for TypedDict (#1074)Marc Mueller2021-06-251-0/+2
|
* Rename non obvious PY3X constant to PY3X_PLUSPierre Sassoulas2021-06-211-4/+4
| | | | See https://github.com/PyCQA/astroid/pull/1069\#issuecomment-865206120
* Fix pep8 in unittest test function's namesPierre Sassoulas2021-06-201-2/+2
|
* Rename astroid.constants to astroid.constPierre Sassoulas2021-06-191-1/+1
| | | | See https://github.com/PyCQA/astroid/pull/1045\#discussion_r654572722
* Remove PY36 constants, we always have PY36Pierre Sassoulas2021-06-171-1/+0
|
* Create a astroid.constants.py to avoid circular importsPierre Sassoulas2021-06-171-5/+4
| | | | And add PY3X type constants in it.
* Import exceptions from astroid.exceptions to avoid circular importsPierre Sassoulas2021-06-151-28/+29
|
* Improve inference of Enum members called "name" and "value" (#1020)Andrew Haigh2021-06-131-1/+55
| | | | | | | | | | | | | | | | | | | | | | | | * 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>
* Update copyright notice for 2.5.7v2.5.7Pierre Sassoulas2021-05-291-1/+3
|
* Remove specific code handling for old version of pytestPierre Sassoulas2021-05-291-3/+0
|
* Fix Use 'from astroid import test_utils' insteadPierre Sassoulas2021-05-291-2/+1
|
* Fix unhandled AstroidSyntaxError raised by infer_named_tuple brain (#929)Andrew Haigh2021-05-291-0/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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)
* Fix six.with_metaclass transformation so it doesn't break user defined ↵Artsiom Kaval2021-05-291-0/+22
| | | | | transformations (#975) * Fix six.with_metaclass transformation so it doesn't break user defined transformations
* Fix crash on random.sample brain (#993)Andrew Haigh2021-05-221-0/+12
| | | | | | | | | | | | | * 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
* Remove check for six tox-environmentMarc Mueller2021-04-241-7/+0
|
* Fix crash when evaluating typing.NamedTuple (#956)Marc Mueller2021-04-211-0/+26
|
* Add inference tip for ``typing.Tuple`` (#948)Marc Mueller2021-04-211-0/+13
|
* Fix import order in unittest_brain.pyPierre Sassoulas2021-04-191-8/+9
|
* Add an isort configuration in setup.cfg and apply itPierre Sassoulas2021-04-191-6/+2
| | | | Except on astroid/__init__.py because of circular imports
* Fix redefining name 'bases' from outer scopePierre Sassoulas2021-04-191-2/+1
|
* Fix Expression is assigned to nothingPierre Sassoulas2021-04-191-0/+1
|
* Fix Unused variable 'meth_inf'Pierre Sassoulas2021-04-191-1/+1
|
* Remove conditional for having pytest, we have pytestPierre Sassoulas2021-04-191-3/+0
|
* Remove python < 3.4 compatibility code for enum modulePierre Sassoulas2021-04-191-18/+0
|
* Fix issue #891Pierre Sassoulas2021-04-101-1/+1
| | | | Remove outdated COPYING and rename COPYING.LESSER
* Modify infernce tip for typing.Generic and typing.Annotated with ↵Marc Mueller2021-04-101-0/+50
| | | | | | | ``__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 (#923)Marc Mueller2021-04-071-49/+167
| | | | | | * Better handling of generic aliases * Use qname for tests mro * Add inference for re.Pattern and re.Match * Add comments
* Use inference_tip for typing.TypedDict brain (#928)Marc Mueller2021-04-071-5/+2
|
* Bug pylint 4206 (#921)hippo912021-04-061-40/+250
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* Prepare for 2.5.2 releaseastroid-2.5.2Pierre Sassoulas2021-03-281-1/+1
|
* Solves "Duplicates found in MROs" false positives. (#905, #916)Marc Mueller2021-02-281-0/+115
| | | | | | | * 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>
* Upgrade copyrite noticePierre Sassoulas2021-02-281-0/+2
|
* Don't transform dataclass ClassVars (#914)Marc Mueller2021-02-281-0/+12
| | | Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
* Small improvementsMarc Mueller2021-02-281-3/+1
|
* Fix testsMarc Mueller2021-02-281-0/+3
|
* Improve typing.TypedDict inferenceMarc Mueller2021-02-281-0/+15
|