Code Monkey home page Code Monkey logo

Comments (5)

thatch avatar thatch commented on June 14, 2024 1

A test for this should go near https://github.com/facebookincubator/Bowler/blob/master/bowler/tests/query.py#L187

To see what the lib2to3 pattern would look like, you can use python -m bowler dump [--selector-pattern] <filename>.

The bug is probably a missing piece of the pattern in https://github.com/facebookincubator/Bowler/blob/master/bowler/query.py#L120 that involves {dotted_name}

Getting started docs are at https://github.com/facebookincubator/Bowler/blob/master/CONTRIBUTING.md

from bowler.

markrofail avatar markrofail commented on June 14, 2024

would like to contribute to this. Can I be assigned?

from bowler.

markrofail avatar markrofail commented on June 14, 2024

I don't think the problem is in {dotted_name}

import testbefore

@testbefore()
class A:
    pass

also fails.

from bowler.

amyreese avatar amyreese commented on June 14, 2024

The selector will need to get more complicated/thorough to catch cases in decorators, since decorators (pre 3.9) have a restricted syntax and use different pieces of the grammar. You can see this by dumping the full parsed CST from your example:

(.venv) jreese@garbodor ~/workspace/bowler master± » cat foo.py
import testbefore

@testbefore()
class A:
    pass

@testbefore.foo()
def func():
    pass
(.venv) jreese@garbodor ~/workspace/bowler master± » bowler dump foo.py
foo.py
[file_input] ''
.  [simple_stmt] ''
.  .  [import_name] ''
.  .  .  [NAME] '' 'import'
.  .  .  [NAME] ' ' 'testbefore'
.  .  [NEWLINE] '' '\n'
.  [decorated] '\n'
.  .  [decorator] '\n'
.  .  .  [AT] '\n' '@'
.  .  .  [NAME] '' 'testbefore'
.  .  .  [LPAR] '' '('
.  .  .  [RPAR] '' ')'
.  .  .  [NEWLINE] '' '\n'
.  .  [classdef] ''
.  .  .  [NAME] '' 'class'
.  .  .  [NAME] ' ' 'A'
.  .  .  [COLON] '' ':'
.  .  .  [suite] ''
.  .  .  .  [NEWLINE] '' '\n'
.  .  .  .  [INDENT] '' '    '
.  .  .  .  [simple_stmt] ''
.  .  .  .  .  [NAME] '' 'pass'
.  .  .  .  .  [NEWLINE] '' '\n'
.  .  .  .  [DEDENT] '\n' ''
.  [decorated] ''
.  .  [decorator] ''
.  .  .  [AT] '' '@'
.  .  .  [dotted_name] ''
.  .  .  .  [NAME] '' 'testbefore'
.  .  .  .  [DOT] '' '.'
.  .  .  .  [NAME] '' 'foo'
.  .  .  [LPAR] '' '('
.  .  .  [RPAR] '' ')'
.  .  .  [NEWLINE] '' '\n'
.  .  [funcdef] ''
.  .  .  [NAME] '' 'def'
.  .  .  [NAME] ' ' 'func'
.  .  .  [parameters] ''
.  .  .  .  [LPAR] '' '('
.  .  .  .  [RPAR] '' ')'
.  .  .  [COLON] '' ':'
.  .  .  [suite] ''
.  .  .  .  [NEWLINE] '' '\n'
.  .  .  .  [INDENT] '' '    '
.  .  .  .  [simple_stmt] ''
.  .  .  .  .  [NAME] '' 'pass'
.  .  .  .  .  [NEWLINE] '' '\n'
.  .  .  .  [DEDENT] '' ''
.  [ENDMARKER] '' ''

Of note is that the selector will need to be expanded to cover use of both the dotted_name and decorator symbols with a single NAME leaf matching the target module. Python grammar is complicated. 😔

from bowler.

amyreese avatar amyreese commented on June 14, 2024

This is also a more general problem with a number of selectors in Bowler where they don't catch 100% of uses of the name, or where being 100% thorough is potentially catching cases where a local could be shadowing the global module name and Bowler doesn't actually know that.

from bowler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.