Giter Club home page Giter Club logo

memestra's People

Contributors

brendan0powers avatar davidbrochart avatar jasongrout avatar johanmabille avatar marimeireles avatar serge-sans-paille avatar sylvaincorlay avatar zangwill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

memestra's Issues

Recursiveness on functions that use functions of imported modules doesn't work

The title might be confusing, but here is an example of what I mean:

       │ File: some_rec_module.py
───────┼──────────────────────────────────────────────────────────────
   1   │ import some_module
   2   │ 
   3   │ def foo():
   4   │     return some_module.foo()
   5   │ 
   6   │ def bar():
   7   │     return some_module.bar()
   8 + │ 
   9 + │ foo()
  10 + │ bar()

memestra tests are sensitive to global mutable state

When running tests for pythons 3.8 and 3.9 after running tests for python 3.7 without the necessary changes to gast and beniget, both to support NamedExprs, the tests pass. With a clean cache (rm -rf $XDG_CONFIG_HOME/memestra) the tests fail as they ought to. Whatever is being stored in $XDG_CONFIG_HOME isn't taking into account enough information to make the behavior of the tool the same as it would be without a cache.

README examples don't work because "decorator.deprecated" doesn't exist. Do you mean "deprecated.deprecated"?

Just a quick question, when I try to run the example in the README, I get an error because import decorator doesn't have a deprecated that we expect. With the same code as the README, Python can't run the script and Memestra produces no output:

cat test.py 
import decorator

@decorator.deprecated
def foo(): pass

def bar():
    foo()

foo()python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import decorator
ImportError: No module named decoratormemestra test.py

However, if I install Deprecated and replace decorator with deprecated in the test, Python and Memestra work as expected:

pip install Deprecated
### snip
Successfully installed Deprecated-1.2.11 wrapt-1.12.1cat test2.py 
import deprecated

@deprecated.deprecated
def foo(): pass

def bar():
    foo()

foo()python test2.py  
test2.py:9: DeprecationWarning: Call to deprecated function (or staticmethod) foo.
  foo()memestra test2.py
foo used at test2.py:7:5
foo used at test2.py:9:1

Just wanted to confirm this. Will be happy to put together a little PR to update README accordingly?

Memestra doesn't work if you're using __init__ imports

I found a case where memestra doesn't work, but I suppose we want it to work:

If you're importing something from init like in here:

https://github.com/numpy/numpy/blob/41e254f96e8d5bd558d2edbf8b198eb4143e8b74/numpy/__init__.py#L155

for example, memestra won't return anything.

A reproducible example of what I mean would be running a file init_test.py with the command memestra init_test.py --decorator=decoratortest.deprecated that contains:

from tests.misc import foo

foo()

in memestra home and adding this line from some_module import foo to the __init__.py in tests/misc.

Memestra doesn't work with methods

Was trying to write an example for the blogpost and got this:

import deprecated


@deprecated.deprecated('This function will be removed on Feb. 2100.')
def some_old_function(x, y):
    return x + y


# You can also decorate a class or a method:
class SomeClass(object):
    @deprecated.deprecated('kkkkk')
    def some_old_method(self, x, y):
        return x + y


@deprecated.deprecated('Use another class.')
class SomeOldClass(object):
    pass


some_old_function(2, 3)

some_obj = SomeClass()

some_obj.some_old_method(4, 5)

SomeOldClass()

Everything is captured by memestra but some_obj.some_old_method(4, 5).

I checked our tests and we're actually not covering it at all. I think we forgot.
Can help on this fix after this hectic week.

Deprecation reasons are missing for code imported from another module

I've created a test case: https://github.com/brendan0powers/memestra_testcase

it's a simple setup with two files, test.py, and testimport.py. In testimport.py, I define a class Test, that is deprecated. It's used in test.py. Memestra correctly reports the usage of the deprecated Test class but does not report the reason for the deprecation.

versions:

beniget                       0.3.0
gast                          0.4.0
memestra                      0.0.6
nbconvert                     5.6.0
nbformat                      4.4.0

output:

$ memestra --recursive test.py
testimport.Test used at test.py:3:5

expected output:

$ memestra --recursive test.py
testimport.Test used at test.py:3:5 This is deprecated

Cannot pip install

$ pip install memestra
Collecting memestra
  Downloading memestra-0.0.1.tar.gz (7.0 kB)
    ERROR: Command errored out with exit status 1:
     command: /home/david/miniforge3/envs/memestra-dev/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4vt5ksze/memestra/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4vt5ksze/memestra/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-93mls65p
         cwd: /tmp/pip-install-4vt5ksze/memestra/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-4vt5ksze/memestra/setup.py", line 5, in <module>
        dev_reqs = open("requirements-dev.txt").read().splitlines()
    FileNotFoundError: [Errno 2] No such file or directory: 'requirements-dev.txt'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Recursive mode doesn't find nested deprecations as expected.

When testing recursive mode in a "real world" scenario, memestra does not find any deprecations. I can reproduce this with a few different Python libraries. I've added steps to reproduce below. This isn't exactly what I'm doing, but it's pretty close.

Steps to reproduce:

Setup the environment

conda create -n memestra-import python=3.7.1 ipywidgets deprecated
conda activate memestra-import

Check out the master branch of memestra, and install it.

pip install -e .

Edit $CONDA_PREFIX/lib/python3.7/site-packages/ipywidgets/widgets/widget_button.py and add this snippet before the declaration of Button

from deprecated import deprecated

@deprecated("Test")

Create a file button.py that contains

from ipywidgets import Button

b = Button()

Run memestra

memestra --recursive button.py

Not showing deprecations for imported modules

With these files:

# decoratortest.py

from decorator import decorate

def _deprecated(func, *args, **kw):
    print('warning:', func.__name__, 'has been deprecated')
    return func(*args, **kw)

def deprecated(func):
    return decorate(func, _deprecated)
# some_module.py

from decoratortest import deprecated

@deprecated
def foo(): pass

def bar(): pass
# test.py

import some_module
from decoratortest import deprecated

@deprecated
def foo(): pass

def bar(): pass

some_module.foo()
some_module.foo()
some_module.bar()
some_module.foo()

foo()
foo()
bar()
foo()

memestra shows the deprecations only for foo(), not for some_module.foo():

$ memestra --decorator=decoratortest.deprecated test.py
foo used at test_code.py:14:1
foo used at test_code.py:15:1
foo used at test_code.py:17:1

Although it seems to work on the CI. The tests show the same error when I run them locally.

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.