Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support python3.5 #218

Merged
merged 5 commits into from
Jan 2, 2019
Merged

support python3.5 #218

merged 5 commits into from
Jan 2, 2019

Conversation

fukatani
Copy link
Contributor

@fukatani fukatani commented Dec 31, 2018

とりあえずテストは通しました。手元ではatcoderだけ軽く試しています。
jsonはdecode('UTF-8')すればいけたのと、Python3.5のargparseは--systemが最後のコマンドライン引数だとエラーになりましたので修正しました。

ついでにbranch名に限らずテストされるようにしました。

Python3.5対応するかどうかはお任せします。(個人的には嬉しいですが、3.6しかやらんぞというのもまた決断)
型アノテーションの書き方はPython3.6で書かれている書き方のほうがわかりやすいですね。

@fukatani
Copy link
Contributor Author

masterブランチでも型アノテーション関連のwarningが出ている気がします。大丈夫でしょうか?

@fukatani fukatani changed the title [WIP] support python3.5 support python3.5 Dec 31, 2018
@kmyk
Copy link
Member

kmyk commented Dec 31, 2018

ありがとうございます。
3.5 対応は可能ならしておきたいものではあるので助かります。

しかしこれをそのままではmergeできないのでいくつか修正をお願いします。

まず型アノテーションの書き方が間違っています。
foo: int = 3 に対応するのは foo = 3 # type: int で、それ以外だと型アノテーションとして認識されません。失敗したと言って閉じた回のもの (216d2e6) が正解なので、これに倣って修正するか単にcherry-pickしてください。

他の細かい指摘はレビュー機能で書いたので見ておいてください。
CIが通ってしまっているのはミスなので後で調査と修正をしておきます。

mypy ログ
$ mypy --ignore-missing-imports oj                      
onlinejudge/dispatch.py:9: error: Need type annotation for 'submissions'
onlinejudge/dispatch.py:19: error: Need type annotation for 'problems'
onlinejudge/dispatch.py:32: error: Need type annotation for 'services'
onlinejudge/implementation/utils.py:103: error: Need type annotation for 'payload'
onlinejudge/implementation/utils.py:104: error: Need type annotation for 'files'
onlinejudge/topcoder.py:168: error: Need type annotation for 'rows'
onlinejudge/topcoder.py:182: error: Need type annotation for 'row'
onlinejudge/aoj.py:57: error: Need type annotation for 'samples'
onlinejudge/aoj.py:75: error: Need type annotation for 'testcases'
onlinejudge/yukicoder.py:222: error: Need type annotation for 'data'
onlinejudge/yukicoder.py:268: error: Need type annotation for 'basenames'
onlinejudge/yukicoder.py:279: error: Need type annotation for 'samples'
onlinejudge/atcoder.py:288: error: Incompatible types in assignment (expression has type "int", variable has type "None")
onlinejudge/atcoder.py:289: error: Incompatible return value type (got "None", expected "int")
onlinejudge/implementation/command/utils.py:42: error: Need type annotation for 'result'
onlinejudge/implementation/command/utils.py:51: error: Need type annotation for 'tests'
onlinejudge/implementation/command/generate_scanner.py:22: error: Need type annotation for 'tokens'
onlinejudge/implementation/command/generate_scanner.py:48: error: Need type annotation for 'env'
onlinejudge/implementation/command/generate_scanner.py:61: error: Need type annotation for 'used'
onlinejudge/implementation/command/generate_scanner.py:80: error: Need type annotation for 'names'
onlinejudge/implementation/command/generate_scanner.py:92: error: Need type annotation for 'body'
onlinejudge/implementation/command/generate_scanner.py:192: error: Incompatible types in assignment (expression has type "List[List[Dict[str, str]]]", variable has type "Optional[str]")
onlinejudge/implementation/command/generate_scanner.py:194: error: Incompatible types in assignment (expression has type "List[Dict[str, Any]]", variable has type "Optional[str]")
onlinejudge/implementation/command/generate_scanner.py:194: error: Argument 1 to "parse" has incompatible type "str"; expected "List[List[Dict[str, Any]]]"
onlinejudge/implementation/command/submit.py:66: error: Incompatible types in assignment (expression has type "None", variable has type "List[Any]")
onlinejudge/implementation/command/submit.py:272: error: Value of type "object" is not indexable
onlinejudge/implementation/command/submit.py:273: error: Value of type "object" is not indexable
onlinejudge/implementation/command/submit.py:274: error: "object" has no attribute "get"
onlinejudge/implementation/command/test.py:82: error: Incompatible types in assignment (expression has type "float", variable has type "int")

@@ -31,9 +31,10 @@ def snippet_call_download(self, url, files, is_system=False, type='files'):
os.chdir(tempdir)
if os.path.exists('test'):
shutil.rmtree('test')
cmd = [ ojtools, 'download', url ]
cmd = [ ojtools, 'download' ]
Copy link
Member

@kmyk kmyk Dec 31, 2018

Choose a reason for hiding this comment

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

以前の形でも動いているのなら無闇に変更箇所を増やさないでほしいですし、何か問題があったのなら黙って修正するのでなく別のコミットに分けてコメントを付けてほしいです。

.travis.yml Outdated
only:
- master
- develop

Copy link
Member

@kmyk kmyk Dec 31, 2018

Choose a reason for hiding this comment

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

消さないでほしいです。
CIから外部のサービスへアクセスをかける性質によりすべてのコミットごとにCIを走らせるのは適切ではないです。

samples: List[TestCase] = []
for sample in json.loads(resp.content):
samples = [] # List[TestCase]
for sample in json.loads(resp.content.decode('utf-8')):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for sample in json.loads(resp.content.decode('utf-8')):
for sample in json.loads(resp.content.decode(resp.encoding)):

たぶんこの方が適切です

Copy link
Member

Choose a reason for hiding this comment

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

他の2箇所も同様にお願いします

@kmyk
Copy link
Member

kmyk commented Dec 31, 2018

#219 をしてCIが動いてなかった問題を修正しました。
今のmasterにrebaseあるいはmergeして (あと d566969 でのrevertでPython 3.5の指定が消えたのでこれも追加して) もう一度CI走らせてください。通ったらmergeします。
よろしくお願いします。

@kmyk
Copy link
Member

kmyk commented Jan 2, 2019

🎉
CI通ったみたいなのでmergeします

@kmyk kmyk merged commit 7aee217 into online-judge-tools:master Jan 2, 2019
@fukatani
Copy link
Contributor Author

fukatani commented Jan 2, 2019

いろいろと不手際ありすいません。丁寧にレビューしてもらい勉強になりました。
--systemの順番を変えたのはテストが通らないため、argparseの仕様が変わったのかな?と思ったのですが、気のせいでした。今やったら普通に通りました。

また、re.matchオブジェクトのインデクシングは(m[0])Python3.6以降でしかサポートされてないのですが、
mypyのチェックで気づきました。mypy導入していただきありがとうございます。

@kmyk
Copy link
Member

kmyk commented Jan 2, 2019

いいえ、最初から完璧というのはありえないですし気にすることではありません。
ありがとうございました。また次もなにか問題があればよろしくお願いします。

また、この修正を反映させた版をuploadしました。pipで更新すれば動くようになると思います。

@fukatani fukatani deleted the python3.5 branch July 6, 2019 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants