Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False negative for SyntaxError::text #1432

Closed
owillebo opened this issue Apr 20, 2017 · 1 comment
Closed

False negative for SyntaxError::text #1432

owillebo opened this issue Apr 20, 2017 · 1 comment
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors

Comments

@owillebo
Copy link

owillebo commented Apr 20, 2017

Steps to reproduce

try:
  pass
except SyntaxError as ex:
  ex.text.rstrip()

Current behavior

E: 4, 2: Class 'text' has no 'rstrip' member (no-member)

Expected behavior

No issue

pylint --version output

pylint 1.7.1,
astroid 1.5.2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)]pylint

@rogalski
Copy link
Contributor

Thanks for submitting an issue!

Some basic debug:

It seems like all non-standard exception instance attributes are inferred as dummy ClassDefs and not actual types.

Given:

import astroid

code = """
try:
  pass
except SyntaxError as ex:
  ex #@
  ex.args #@
  ex.text #@
  ex.lineno #@
"""

for node in astroid.extract_node(code):
    print(node.as_string(), *node.infer())

We receive:

ex Instance of builtins.SyntaxError
ex.args Tuple.tuple(ctx=None,
            elts=(<Const.str l.None at 0x10f16e470>,))
ex.text ClassDef.text(name='text',
              doc='exception text',
              decorators=None,
              bases=[],
              body=[])
ex.lineno ClassDef.lineno(name='lineno',
                doc='exception lineno',
                decorators=None,
                bases=[],
                body=[])

Our interpreter.objectmodel.ExceptionInstanceModel define some extra logic for .args and .__traceback__ which exists for all BaseInstance subclasses, but I'm not sure how class-specific attributes (like those in this issue) should be handled.

@PCManticore PCManticore added the Good first issue Friendly and approachable by new contributors label May 14, 2018
clrpackages pushed a commit to clearlinux-pkgs/astroid that referenced this issue Feb 28, 2019
…ed single and double quotes.

Azeem Bande-Ali (1):
      Docs: Fixing transformation example to be functional (#640)

Benjamin Elven (1):
      Added 2 more missing _ssl constants (#648)

Bianca Power (1):
      Fix typo in description for brain_attrs (#638)

Claudiu Popa (48):
      Add reversed() to Enum classes
      Use a string for the name of the enum instead of grabbing it as a variable
      Added special support for `enum.IntFlag`
      Pin typed_ast so a new release won't break the pylint's pragmas
      Fix a bug where an Attribute used as a base class was triggering a crash
      Add missing _ssl constant. Close pylint-dev/pylint#2629
      ``typing`` types have the `__args__` property. Close pylint-dev/pylint#2419
      Make sure the test does not crash if the directory already exists
      Revert path copying in InferenceContext()
      Prevent crashing when processing ``enums`` with mixed single and double quotes.
      Move infer_name_module() in pylint and remove it from here
      Remove test that does not work actually work consistently on all Python versions
      Disable the pylint job until we fix the clone inference bugs
      Revert "Disable the pylint job until we fix the clone inference bugs"
      Add brain tips for `http.client`. Close pylint-dev/pylint#2687
      Revert "Remove the restore_path() method"
      Add a registry for builtin exception models. Close pylint-dev/pylint#1432
      Disable test on Python 3.4
      Change the filter to use equal
      Use a different prefix for the object model methods
      Added more builtin exceptions attributes. Close #580
      Remove StopIteration handling which should not leak at all from inference
      Replace a couple of returns with explicit InferenceError exceptions
      Make sure that Attribute.infer has a protection against StopIterations
      Add a method to the manager to retrieve the builtins module
      Remove the restriction that "old style classes" cannot have a MRO.
      Remove inadvertent test which still does not have a fix
      Adjust the pull request template a little bit
      Make the astroid bootstrapping take care of builtins such as Generator
      Prepare a dev release
      Fix a recursion error caused by inferring the ``slice`` builtin.
      Bump typed_ast to 1.2.0
      ``brain_numpy`` returns an undefined type for ``numpy`` methods to avoid ``assignment-from-no-retur
      Remove inadvertent returns from class bodies
      Fix a crash in the ``enum`` brain tip caused by non-assign members in class definitions.
      Support non-const nodes as values of Enum attributes.
      Add a proper ``strerror`` inference to the ``OSError`` exceptions.
      Fix a crash with ``typing.NamedTuple`` and empty fields. Close pylint-dev/pylint#2745
      Update to typed-ast 1.3 and drop the Python 3.7 restriction
      Install typed ast 1.3 for Python 3.7 and earlier versions for Python 3.6
      Do a new dev release
      Use the same versions in tox as in __pkginfo__
      Use the right pytest methods for setup and teardown
      Don't clear the manager caching any longer
      Remove merge marker
      Prepare 2.2.0
      Disable test that does not make sense on versions older than Python 3.6
      When picking the parse function, make sure to parse with the right minor version

Nick Drozd (1):
      Cut generator flags

Peter Talley (1):
      Add new Popen kwarg 'text' in Python 3.7

Tomas Gavenciak (2):
      Remove else after return/raise
      Extend detection of classes defined with attr

hippo91 (11):
      Just breakpoint to debug and mark the origin of the problem
      Revert "Just breakpoint to debug and mark the origin of the problem"
      Refactoring chained comparison (#636)
      Avoid statement deletion in the _filter_stmts method of the LookupMixin class for PartialFunction
      Adding support for unary operators for numpy ndarray and numbers. Adding hook to filter results of infer_call_result from list and tuples for function array and linspace
      Refactoring to code DRY
      Add a unittest checking that the call to numpy.array function is not inferred as a list or a tuple
      Refactors and generalizes unittests dealing with tuple or list inference of numpy function calls
      Add of ChangeLog entry
      Format according to Black
      Add support of unary operators to numpy types.

What's New in astroid 2.2.0?
============================
Release Date: 2019-02-27

* Fix a bug concerning inference of calls to numpy function that should not return Tuple or List instances.

 Close pylint-dev/pylint#2436

* ``typed_ast`` gets installed for Python 3.7, meaning type comments can now work on 3.7.

* Fix a bug concerning inference of unary operators on numpy types.

  Close pylint-dev/pylint#2436 (first part)

(NEWS truncated at 15 lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors
Projects
None yet
Development

No branches or pull requests

3 participants