Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

add some helpful predicates #60

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

add some helpful predicates #60

wants to merge 16 commits into from

Conversation

lime-green
Copy link
Contributor

@lime-green lime-green commented Nov 23, 2018

These predicates are meant to be general-use (call node) predicates to be used for visitor and inference-tip functions

@codecov
Copy link

codecov bot commented Nov 23, 2018

Codecov Report

Merging #60 into master will increase coverage by 0.42%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
+ Coverage   93.41%   93.83%   +0.42%     
==========================================
  Files          10       11       +1     
  Lines         395      422      +27     
  Branches       57       64       +7     
==========================================
+ Hits          369      396      +27     
  Misses         15       15              
  Partials       11       11
Flag Coverage Δ
#py27 93.83% <100%> (+0.42%) ⬆️
#py36 93.83% <100%> (+0.42%) ⬆️
#py37 93.83% <100%> (+0.42%) ⬆️
Impacted Files Coverage Δ
codewatch/__init__.py 100% <100%> (ø) ⬆️
codewatch/predicates.py 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 466b7f2...10dfe83. Read the comment docs.

eg.

```
from my_models import Grade
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a more generic example than Grade (here and throughout the project)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated, but still an issue.

codewatch/predicates.py Outdated Show resolved Hide resolved
codewatch/predicates.py Outdated Show resolved Hide resolved

class CallNodePredicates(object):
@staticmethod
def does_node_call_method(call_node, method_name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky. 😓

Though we found use for it in that large codebase, I'm not sure we want to encourage use of this predicate widely. It has some limitations (being based solely on matching symbol names) that seem surprising and a bit under-powered to be a part of our standard interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit under-powered but I think it's generally useful

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codewatch/predicates.py Outdated Show resolved Hide resolved

class CallNodePredicates(object):
@staticmethod
def has_expected_chain_name(call_node, method_name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the plus side, this new name is much better!

I'm still worried that this provides a seemingly-easy way to use codewatch (that we seem to want to encourage, by including it in the API) that won't actually do what people hope and will trigger subtle mistakes over time. My interpretation of why this is useful is that we've found inference so complex and unreliable that we're resorting to predicates by symbol names. This makes me unhappy.

Put another way, the biggest reason I don't like this is that it feels like giving up on the actual value of the AST approach. There's a not-so-tough regex that could be written to do this with grep. It's straight up textual-matching.

If we really want to include this, I'd be much happier if it was in a way that:
(a) made it more obvious that this should be an approach of last resort and
(b) included lots of warnings that this can easily fail to detect all kinds of different restatements of identical logic to the specified call chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ok. Yes it is indeed straight up text matching but it works alongside the rest of codewatch and is a good way to get started IMO

I'll include some warnings then

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants