Comments (5)
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.
would like to contribute to this. Can I be assigned?
from bowler.
I don't think the problem is in {dotted_name}
import testbefore
@testbefore()
class A:
pass
also fails.
from bowler.
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.
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)
- libCST support HOT 1
- pybowler.io TLS certificate has expired HOT 1
- Templates for common refactorings HOT 4
- Migrate Website to Docusaurus 2 Alpha
- how to handle moved function? HOT 1
- How to select strings and put an 'r' in front? HOT 4
- Do defaults to execute work?
- What are the restrictions on chaining select methods? HOT 4
- Refactoring Python 2.7 files does not work (parse error on print statement) HOT 4
- Some kind of test that verifies the requirements.txt is enough to run the tests
- Rename methods HOT 2
- Unable to chain remove_argument() HOT 5
- Question: I have a working select and modifier but want it to remove the matched node, can only make the node a blank line HOT 3
- Crash on functions with certain typehinting HOT 4
- Unable to apply hunk to file without trailing newline HOT 1
- Doc bugs: what is the syntax for `bowler test`?, obsolete or future-functionality documentation, and a doc info request HOT 1
- bowler/README.md documents `rename_function` however this functionality does not appear to exist
- Bowler should include docs on how to test/debug/understand lib2to3 patterns
- Ingore notebook syntax HOT 1
- `modify_argument` loses the trailing `,` in call arguments HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bowler.