Skip to content

Commit

Permalink
Merge pull request #10 from eriknw/py37
Browse files Browse the repository at this point in the history
Support Python 3.7
  • Loading branch information
eriknw committed Sep 9, 2020
2 parents 4687c27 + 5cadce2 commit c5248c8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ os: linux
dist: xenial

python:
- "3.8"
- 3.7
- 3.8
- "3.9-dev"

install:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Innerscope

[![Python Version](https://img.shields.io/badge/python-3.8%20%7C%203.9-blue)](https://img.shields.io/badge/python-3.8%20%7C%203.9-blue)
[![Python Version](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9-blue)](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9-blue)
[![Version](https://img.shields.io/pypi/v/innerscope.svg)](https://pypi.org/project/innerscope/)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/eriknw/innerscope/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/eriknw/innerscope.svg?branch=master)](https://travis-ci.org/eriknw/innerscope)
Expand Down
44 changes: 42 additions & 2 deletions innerscope/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,48 @@
import functools
import inspect
from collections.abc import Mapping
from types import CellType, CodeType, FunctionType
from types import CodeType, FunctionType
from tlz import concatv, merge

try:
# Added in Python 3.8
from types import CellType

def code_replace(code, *, co_code, co_names, co_stacksize):
return code.replace(
co_code=co_code,
co_names=co_names,
co_stacksize=co_stacksize,
)


except ImportError:

def CellType(x):
def inner(): # pragma: no cover
return x

return inner.__closure__[0]

def code_replace(code, *, co_code, co_names, co_stacksize):
return CodeType(
code.co_argcount,
code.co_kwonlyargcount,
code.co_nlocals,
co_stacksize,
code.co_flags,
co_code,
code.co_consts,
co_names,
code.co_varnames,
code.co_filename,
code.co_name,
code.co_firstlineno,
code.co_lnotab,
code.co_freevars,
code.co_cellvars,
)


def _get_globals_recursive(func, *, seen=None, isclass=False):
""" Get all global names used by func and all functions and classes defined within it."""
Expand Down Expand Up @@ -397,7 +436,8 @@ def __init__(self, func, *mappings, use_closures=True, use_globals=True):
self._code = None
else:
# stacksize must be at least 3, because we make a length three tuple
self._code = code.replace(
self._code = code_replace(
code,
co_code=co_code,
co_names=co_names,
co_stacksize=max(code.co_stacksize, 3),
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
url="https://github.com/eriknw/innerscope",
packages=find_packages(),
license="BSD",
python_requires=">=3.8",
python_requires=">=3.7",
setup_requires=[],
install_requires=["toolz"],
tests_require=["pytest"],
Expand All @@ -27,6 +27,7 @@
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython",
Expand Down

0 comments on commit c5248c8

Please sign in to comment.